﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LabMS.Common
{
    public class codehelper
    {
        ///<summary>
        /// Html Encode
        ///</summary>
        ///<param name = "str">string </param>
        ///<returns>string</returns>
        ///
        public static string Encode(string str)
        {
            str = str.Replace("&", "&amp;");
            str = str.Replace("'", "''");
            str = str.Replace("\"", "&quot;");
            str = str.Replace(" ", "&nbsp;");
            str = str.Replace("<", "&lt;");
            str = str.Replace(">", "&gt;");
            str = str.Replace("\n", "<br/>");

            return str;

        }

        ///<summary>
        ///decode
        ///</summary>
        ///<param name = "str">string </param>
        ///<returns>string</returns>
        ///
        public static string Decode(string str)
        {
            str = str.Replace("<br/>", "\n");
            str = str.Replace("&gt;", ">");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("&quot;", "\"");
            return str;
        }
    }
}
